#ifndef __K_CTYPE_H__
#define __K_CTYPE_H__

#define _CL		0x01	/* lower */
#define _CU		0x02	/* upper */
#define _CP		0x04	/* puct */
#define _CD		0x08	/* digit */
#define _CX		0x10	/* hex digit */
#define _CS		0x20	/* blank */
#define _CSP	0x40	/* space */
#define _CC		0x80	/* ctrl */

extern unsigned char __ctype[];

#define isalnum(c) ((__ctype+1)[(int)c]&(_CU|_CL|_CD))
#define isalpha(c) ((__ctype+1)[(int)c]&(_CU|_CL))
#define isdigit(c) ((__ctype+1)[(int)c]&(_CD))
#define isgraph(c) ((__ctype+1)[(int)c]&(_CP|_CU|_CL|_CD))
#define islower(c) ((__ctype+1)[(int)c]&(_CL))
#define isprint(c) ((__ctype+1)[(int)c]&(_CP|_CU|_CL|_CD|_CSP))
#define ispunct(c) ((__ctype+1)[(int)c]&(_CP))
#define isspace(c) ((__ctype+1)[(int)c]&(_CS))
#define isupper(c) ((__ctype+1)[(int)c]&(_CU))
#define isxdigit(c) ((__ctype+1)[(int)c]&(_CD|_CX))
#define iscntrl(c) ((__ctype+1)[(int)c]&(_CC))

#define isascii(c) (((unsigned int)(c)) <= 127)
#define toascii(c) (((unsigned int)(c)) & 127)

/*
 * TODO: The above macros are not thread safe. Maybe
 * if a temporary variable was used, it would be better?
 */
extern char __cfc;
#define tolower(c) (__cfc=(c), isupper(__cfc) ? __cfc+('a'-'A') : __cfc)
#define toupper(c) (__cfc=(c), islower(__cfc) ? __cfc-('a'-'A') : __cfc)

#endif /* __K_CTYPE_H__ */
